package vip.meet.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import vip.meet.type.UserStatus;


public class UserStatusHandler implements TypeHandler<UserStatus> {

    @Override
    public void setParameter(PreparedStatement ps, int i, UserStatus enableOrDisableStatus, JdbcType jdbcType) throws SQLException {
        ps.setInt(i, enableOrDisableStatus == null ? UserStatus.VALID.getId() : enableOrDisableStatus.getId());
    }

    @Override
    public UserStatus getResult(ResultSet resultSet, String columnName) throws SQLException {
        return UserStatus.getInstance(resultSet.getInt(columnName));
    }

    @Override
    public UserStatus getResult(ResultSet resultSet, int columnIndex) throws SQLException {
        return UserStatus.getInstance(resultSet.getInt(columnIndex));
    }

    @Override
    public UserStatus getResult(CallableStatement callableStatement, int columnIndex) throws SQLException {
        return UserStatus.getInstance(callableStatement.getInt(columnIndex));
    }


}
